#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <tuple>
using namespace std;

template <class T, class U> // 类模板，用于代替不同类型执行相同操作
ostream &operator<<(ostream &os, pair<T, U> &p)
{ // <<的重载
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

// 定义函数对vector进行输出
void cout_vec(vector<int> &temp)
{
    for (size_t i = 0; i < temp.size(); i++)
    {
        cout << temp[i] << " ";
    }
    cout << endl;
}

struct book
{
    string name;
    float price;
    int amount;
};

bool price_compare(book book1, book book2)
{ // 对结构体进行自定义排序，价格高得排在前面
    if (book1.price > book2.price)
    {
        return true;
    }
    return false;
}
int main()
{

    // vector中pair的两种构造方式,注意，vector只能包含两个数组，vector<int,int,int>是错误的
    vector<pair<int, int>> vec_pair{make_pair(4, 3), make_pair(5, 2), make_pair(1, 11)};
    vec_pair.push_back(pair<int, int>(6, 6));

    // vector中pair的输出方式一
    sort(vec_pair.begin(), vec_pair.end());
    for (size_t i = 0; i < vec_pair.size(); i++)
    {
        cout << vec_pair[i].first << " " << vec_pair[i].second << endl;
    }

    // vector中pair的输出方式二，使用tie接受pair中的元素
    int first, second;
    for (size_t i = 0; i < vec_pair.size(); i++)
    {
        tie(first, second) = vec_pair[i];
        cout << first << " " << second << endl;
    }

    // vector中pair的输出方式三，重载输出运算符
    for (size_t i = 0; i < vec_pair.size(); i++)
    {
        cout << vec_pair[i] << endl;
    }

    vector<book> books;
    book physics{"physics", 24.8, 10};
    book math{"math", 29.9, 13};
    book philosophy{"philosophy", 30.5, 154};
    books.insert(books.begin(), (physics, math, philosophy)); // 注意，这里只会插入philosophy，因为逗号是表达式连接符，只会返回最后一个元素
    books.insert(books.begin(), {physics, math, philosophy}); // 这里就是全部批量在开头位置进行插入了，push_back()同理，也能这么操作.vector<book> books{physics, math, philosophy};也能进行批量插入
    for (size_t i = 0; i < books.size(); i++)
    { // 最后的输出顺序是physics,math,philosophy,philosophy
        cout << books[i].name << endl;
        cout << books[i].price << endl;
        cout << books[i].amount << endl;
    }
    cout << "===================" << endl;

    books.erase(books.begin(), books.begin() + 2); // 删除前两个元素
    for (size_t i = 0; i < books.size(); i++)
    { // 最后的输出顺序是philosophy,philosophy
        cout << books[i].name << endl;
        cout << books[i].price << endl;
        cout << books[i].amount << endl;
    }
    cout << "====================" << endl;

    books.clear(); // 元素清空
    books.insert(books.begin(), {physics, math, philosophy});

    sort(books.begin(), books.end(), price_compare); // 对结构体进行自定义排序，价格高得排在前面
    for (size_t i = 0; i < books.size(); i++)
    {
        cout << books[i].name << endl;
        cout << books[i].price << endl;
        cout << books[i].amount << endl;
    }

    vector<string, book> books_test;

    // 定义动态矩阵
    int m = 4;
    int n = 4;
    int k = 4;
    vector<vector<char>> maze(m, vector<char>(n, ' ')); // maze为vector<vector<char>>，第一个vector为m，第二个vector为vector<char>(n, ' ')，相当于mxn的矩阵

    vector<vector<vector<char>>> maze(k, vector<vector<char>>(m, vector<char>(m, ' '))); // maze为k个mxn矩阵
    maze[0][0] = 'a';
    for (size_t i = 0; i < maze.size(); i++)
    {
        cout << maze[i][0];
    }
}